<template>
  <div style="text-align: left">
    <div style="width: 100%;margin-bottom: 20px">
      <el-button type="danger" @click="acquires">一键获取</el-button>
    </div>
    <el-tree :data="treeData" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
  </div>
</template>

<script>
  export default {
    name: "kpiTree",
    data() {
      return {
        treeData:[],
        defaultProps: {
          children: 'children',
          label: 'name'
        }
      };
    },
    mounted(){
      this.loadFun()
    },
    methods: {
      loadFun(){
        let that = this;
        that.$post('vpo/md/answer', {})
          .then((response) => {
            console.log(response);
            that.treeData=response.data
          }).catch(err => {
          that.$message.error(err);
        })
      },
      handleNodeClick(data) {
        console.log(data);
      },

      // 一键获取
      acquires(){
        let that = this;
        const loading = that.$loading({
          lock: true,
          text: "拼命查询中",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)"
        });
        that.$post('pi/data/syncKpi', {})
          .then((response) => {
            if(response.resultCode == 1){
              this.$message({
                message: response.msg,
                type: 'success'
              })
              that.loadFun()
            }else{
              that.$message.error(err);
            }
            loading.close();
          }).catch(err => {
          that.$message.error(err);
          loading.close();
        })
      }
    }
  }
</script>

<style scoped>

</style>
